<? if (!$blocks):?>
	У вас нет ни одного блога. Добавьте <a href="/admin/pages/add">здесь</a>.
<? else: ?>
<form method="post" id="blogForm" action="/admin/articles/add<?=(isset($page->id))?'/'.$page->id:''?>">
	<select name="tblog" id="tBlog">
	<? foreach ($blocks as $block):?>
		<option value="<?=$block->id?>" <? if (isset($page->tBlog) && $block->id == $page->tBlog) echo "selected";?>><?=$block->pName?></option>
	<? endforeach; ?>
	</select>

	<input type="hidden" value="0" id="cropOnSave" name="cropOnSave"/>

	<a href="/admin/articles/add">Добавить еще</a>

	<? if (isset($page->id)):?>
		<a href="<?=base_url().$blocks[$page->tBlog]->pUrl.'/'.$page->pUrl?>" target="_blank">Просмотреть</a>
		<input type="hidden" name="id" value="<?=$page->id?>">
	<? endif;?>

	<? if (isset($page->dDeleted) && ((int)$page->dDeleted > 0)):?>
		<span class="topInfoBlock">
			Статья удалена
		<? if ($this->user->checkRight(2)): ?>
			| <span data-manage="3" data-art="<?=$page->id?>" class="linkStyled manageButton">Восстановить</span>
		<? endif;?>
		</span>
	<? endif;?>

	<table style="width:100%" class="noHighLight">
		<tr>
		<td style="width:300px; vertical-align:top;">
			<table>
				<tr>
					<td>Название</td>
					<td><input type="text" id="nameInput" name="name" value="<?=isset($page->pName)?$page->pName:''?>"></td>
				</tr>
				<tr>
					<td>Адрес</td>
					<td><input type="text" id="addressInput" name="address" value="<?=isset($page->pUrl)?$page->pUrl:''?>"></td>
				</tr>
				<tr>
					<td>Категории</td>
					<td>
						<div id="categoriesDiv">
							<select id="tCategory" multiple>
							<? foreach ($categories as $сategory):?>
								<option value="<?=$сategory->id?>" data-page="<?=$сategory->tPage?>" <? if ( in_array($сategory->id, $articleCategories) ) echo 'selected="selected"';?>>
									<?=$сategory->pName?>
								</option>
							<? endforeach; ?>
							</select>
						</div>
					</td>
				</tr>
			</table>
			
			<input type="button" id="saveButton" value="Сохранить"/>
			<input type="submit" name="delete" value="Удалить"/>

			<div class="bordered" style="display:table; padding:5px;">
				<input type="hidden" size="80" name="pOriginalImg" id="poImgInput" autocomplete="off" value="<?=(empty($page->pOriginalImg))?'':substr(base_url(), 0, -1).$page->pOriginalImg?>"/>
				<a href="#" id="uploadButton">Загрузить картинку статьи</a>
				<a href="#" id="cropImage">Обрезать</a><br/>
				<a href="#" id="restoreImage">Восстановить оригинал</a>
				<div id="ajaxResponse">
					<div id="uploadImgDiv">
						<? if (!empty($page->id) && (!empty($page->pImg))): ?>
							<img src="<?=base_url().'uploads/articles/'.$page->id.'/thumb200/'.$page->pImg.'?'.now()?>" width="200"/>
						<? endif; ?>
					</div>
					<div id="cropDiv" style="display:none">
						<div id="cropDivManage">
							<div>
								<div id="cropDivManageImgPreviewDiv">
									<img src="/pool.jpg" id="cropDivManageImgPreview" />
								</div>
								<table id="cropMetrix" class="noHighLight">
									<tr>
										<td>cx</td>
										<td>cy</td>
										<td>cx2</td>
										<td>cy2</td>
										<td>cw</td>
										<td>ch</td>
										<td></td>
									</tr>
									<tr>
										<td><input type="text" name="c[x]" value="0"/></td>
										<td><input type="text" name="c[y]" value="0"/></td>
										<td><input type="text" name="c[x2]" value="0"/></td>
										<td><input type="text" name="c[y2]" value="0"/></td>
										<td><input type="text" name="c[w]" value="0"/></td>
										<td><input type="text" name="c[h]" value="0"/></td>
										<td><button id="cropMetrixButton">OK</button></td>
									</tr>
								</table>
							</div>
							<div id="cropDivManageImg"></div>
						</div>
					</div>
				</div>
			</div>
		</td>
		
		<td>
			<label>
				<input type="radio" name="inputType" class="inputType" value="markitup">MarkItUp
			</label>
			<label>
				<input type="radio" name="inputType" class="inputType" value="tinymce" checked="true">TinyMCE
			</label>
			<div id="pageTextDiv_markitup" style="display:none">
				<textarea name="text_m" class="pageText"><?=isset($page->pText)?trim(htmlspecialchars($page->pText)):''?></textarea>
				<br>Краткое описание для списка:
				<textarea name="stext_m" class="pageText"><?=isset($page->pShortText)?trim(htmlspecialchars($page->pShortText)):''?></textarea>
			</div>
			<div id="pageTextDiv_tinymce">
				<textarea name="text_t" class="pageText_tiny"><?=isset($page->pText)?trim(htmlspecialchars($page->pText)):''?></textarea>
				<br>Краткое описание для списка:
				<textarea name="stext_t" class="pageText_tiny"><?=isset($page->pShortText)?trim(htmlspecialchars($page->pShortText)):''?></textarea>
			</div>

			<div class="settingsBlock block">
				<b>Дополнительные стили:</b> <br>
				<div id="addStylesListDiv">
				<? foreach ($addStyles as $style):?>
					<div data-id="<?=$style->id?>" class="oneStyle">
						<?=$style->pUrl?>
						<img src="<?=base_url()?>img/admin/remove.png" height="14" onClick="delStyle(this)" class="removeImg"/>
					</div>
				<? endforeach; ?>
				</div>
				<input type="hidden" id="delAddStyles" name="delAddStyles"/>
				<input type="hidden" id="newAddStyles" name="newAddStyles"/>
				<input type="text" id="newStyle"/>
				<br>
				<a href="javascript:addStyle();">Добавить стиль</a>
				
				<hr>
				<b>Дополнительные скрипты:</b> <br>
				<div id="addScriptsListDiv">
				<? foreach ($addScripts as $script):?>
					<div data-id="<?=$script->id?>" class="oneScript">
						<?=$script->pUrl?>
						<img src="<?=base_url()?>img/admin/remove.png" height="14" onClick="delScript(this)" class="removeImg"/>
					</div>
				<? endforeach; ?>
				</div>
				<input type="hidden" id="delAddScripts" name="delAddScripts"/>
				<input type="hidden" id="newAddScripts" name="newAddScripts"/>
				<input type="text" id="newScript"/>
				<br>
				<a href="javascript:addScript();">Добавить скрипт</a>
			</div>
		</td>
		</tr>
	</table>
</form>
<? endif; ?>

<script>
	pageId = <?=isset($page->id)?$page->id:0?>;
</script>